package easy;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Solution_349 {
    public static int[] intersection(int[] nums1, int[] nums2) {

        List<Integer> realA = new ArrayList(Arrays.asList(nums1));
        List<Integer> realB = new ArrayList(Arrays.asList(nums2));
        realA.retainAll(realB);
        int[] r = new int[realA.size()];
        for (int i = 0; i < realA.size(); i++) {
            r[i] = realA.get(i);
        }
        return r;
        /*Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums1) {
            if (!map.containsKey(num)) {
                map.put(num, 1);
            }
        }
        for (int num : nums2) {
            if (map.containsKey(num)) {
                map.put(num, 2);
            }
        }
        List<Integer> list = new ArrayList<>();
        map.forEach((key, val)->{
            if (val>1) {
                list.add(key);
            }
        });
        int[] r = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            r[i] = list.get(i);
        }
        return r;*/
    }

    public static void main(String[] args) {
        int[] intersection = intersection(new int[]{1, 2, 2, 1}, new int[]{});
        for (int i : intersection) {
            System.out.print(i+",");
        }
    }
}
